﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Demo.Api.Migrations
{
    public partial class InitialMigration : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "tab_affair",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false),
                    Name = table.Column<string>(type: "TEXT", maxLength: 1023, nullable: false),
                    FlowChartId = table.Column<long>(type: "INTEGER", nullable: false),
                    Remarks = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tab_affair", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tab_affair_object",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false),
                    AffairId = table.Column<long>(type: "INTEGER", nullable: false),
                    FlowChartId = table.Column<long>(type: "INTEGER", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: true),
                    Type = table.Column<int>(type: "INTEGER", nullable: false),
                    Num = table.Column<int>(type: "INTEGER", nullable: false),
                    Manager = table.Column<string>(type: "TEXT", nullable: true),
                    Director = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tab_affair_object", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tab_flow_chart",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: true),
                    Remarks = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tab_flow_chart", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tab_flow_chart_process",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false),
                    AffairId = table.Column<long>(type: "INTEGER", nullable: false),
                    AffairProcessId = table.Column<long>(type: "INTEGER", nullable: false),
                    FlowChartId = table.Column<long>(type: "INTEGER", nullable: false),
                    NodeId = table.Column<long>(type: "INTEGER", nullable: false),
                    RuleId = table.Column<long>(type: "INTEGER", nullable: false),
                    NodeType = table.Column<int>(type: "INTEGER", nullable: false),
                    OperatingNodeType = table.Column<int>(type: "INTEGER", nullable: false),
                    OperatingTime = table.Column<DateTime>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tab_flow_chart_process", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tab_line",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false),
                    FlowChartId = table.Column<long>(type: "INTEGER", nullable: false),
                    HeadNodeId = table.Column<long>(type: "INTEGER", nullable: false),
                    TailNodeId = table.Column<long>(type: "INTEGER", nullable: false),
                    LineType = table.Column<int>(type: "INTEGER", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: true),
                    Code = table.Column<string>(type: "TEXT", nullable: true),
                    Remarks = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tab_line", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tab_node",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false),
                    FlowChartId = table.Column<long>(type: "INTEGER", nullable: false),
                    Name = table.Column<string>(type: "TEXT", nullable: true),
                    NodeType = table.Column<int>(type: "INTEGER", nullable: false),
                    Logic = table.Column<int>(type: "INTEGER", nullable: false),
                    OrClear = table.Column<bool>(type: "INTEGER", nullable: false),
                    SeparateNodeId = table.Column<long>(type: "INTEGER", nullable: false),
                    RuleId = table.Column<long>(type: "INTEGER", nullable: false),
                    PositionX = table.Column<long>(type: "INTEGER", nullable: false),
                    PositionY = table.Column<long>(type: "INTEGER", nullable: false),
                    Code = table.Column<string>(type: "TEXT", nullable: true),
                    Remarks = table.Column<string>(type: "TEXT", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tab_node", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tab_process_line",
                columns: table => new
                {
                    Id = table.Column<long>(type: "INTEGER", nullable: false),
                    AffairProcessId = table.Column<long>(type: "INTEGER", nullable: false),
                    LineId = table.Column<long>(type: "INTEGER", nullable: false),
                    OperatingTime = table.Column<DateTime>(type: "TEXT", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tab_process_line", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "tab_reverse_clear_line_node",
                columns: table => new
                {
                    NodeId = table.Column<long>(type: "INTEGER", nullable: false)
                        .Annotation("Sqlite:Autoincrement", true),
                    LineId = table.Column<long>(type: "INTEGER", nullable: false),
                    FlowChartId = table.Column<long>(type: "INTEGER", nullable: false),
                    Id = table.Column<long>(type: "INTEGER", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_tab_reverse_clear_line_node", x => x.NodeId);
                });

            migrationBuilder.InsertData(
                table: "tab_flow_chart",
                columns: new[] { "Id", "Name", "Remarks" },
                values: new object[] { 1L, "第一个流程", null });

            migrationBuilder.InsertData(
                table: "tab_node",
                columns: new[] { "Id", "Code", "FlowChartId", "Logic", "Name", "NodeType", "OrClear", "PositionX", "PositionY", "Remarks", "RuleId", "SeparateNodeId" },
                values: new object[] { 1L, null, 1L, 1, "开始", 1, false, 0L, 0L, null, 0L, 0L });
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "tab_affair");

            migrationBuilder.DropTable(
                name: "tab_affair_object");

            migrationBuilder.DropTable(
                name: "tab_flow_chart");

            migrationBuilder.DropTable(
                name: "tab_flow_chart_process");

            migrationBuilder.DropTable(
                name: "tab_line");

            migrationBuilder.DropTable(
                name: "tab_node");

            migrationBuilder.DropTable(
                name: "tab_process_line");

            migrationBuilder.DropTable(
                name: "tab_reverse_clear_line_node");
        }
    }
}
